Skip to content

fix(cli): refuse --importance outside 1-10 on create and update as a usage error - #1428

Open
swastiktawate wants to merge 1 commit into
pyrite-wiki:devfrom
swastiktawate:fix/1393-importance-range
Open

swastiktawate wants to merge 1 commit into
pyrite-wiki:devfrom
swastiktawate:fix/1393-importance-range

Conversation

@swastiktawate

Copy link
Copy Markdown
Contributor

pyrite create and pyrite update accepted any integer for --importance even though the help says 1-10. An importance of 999 or -5 was written to the entry without complaint. This adds min=1, max=10 to the --importance option on both commands so Typer refuses out-of-range values with a clean usage error (exit 2), the way other bounded options already do. Values 1 and 10 stay valid.

Fixes #1393

Test plan: 10 new tests in tests/test_cli_importance_range.py using the cli_world fixture: create --importance 999, 0, and -5 exit 2 naming --importance with no file written; create --importance 1 and 10 exit 0; update --importance 11, 0, and -1 exit 2 with the entry file byte-for-byte unchanged; update --importance 1 and 10 exit 0. Verified by hand that --importance 999 now prints Error: Invalid value for '--importance' / '-i': 999 is not in the range 1<=x<=10. with error code USAGE_ERROR. Ran the neighboring suites: 405 tests in test_cli_commands, test_changelog_fragments, test_cli_usage_error_plain, and test_cli_errors, all passing. Ruff check and format clean.

@markramm markramm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review. I'm an AI agent that triages pull requests for this project's maintainer. A person reads these and makes the final call. If I've got something wrong, say so here.

Thank you for this fix. It is small and well aimed, and the PR body explains clearly what you checked.

Matches the issue: The change adds min=1, max=10 to --importance on create (entry_commands.py:312) and update (:542), the two-line change the groom on #1393 describes. Out-of-range values now exit 2 as a usage error, and 1 and 10 are still accepted.

Overlaps another open pull request: #1381, #1374, #1367 and #1311 also edit pyrite/cli/entry_commands.py. Their hunks are in other places (_report_link, delete_entry, imports, and the bodies of add_entry and update_entry), and none touches the --importance lines. Whichever lands second will need a rebase, but I see no shared lines.

Property coverage: The groom says "Whether the MCP create refuses 999 is not checked: out of scope here; note what you find in the PR." The PR body does not mention MCP. Other importance options in the checkout are read-side filters: browse_commands.py:450 (changed by #1427), read_cli.py:226 (changed by #1416), and link_commands.py:647, which has no bounds and which no open PR touches.

Tests: The tests go through the CLI entry point (world.cli). By my reading the out-of-range cases would exit 0 on dev, so they fail without the change. The text checks match the plain Error: ... line, so tests.cli_help.plain() is not needed. Two gaps against the groom: the acceptance names "error_code": "USAGE_ERROR" but no test asserts it (the create tests already pass --format json); and the regime "update without --importance (unchanged, None)" has no test. runner = CliRunner() in the test file is defined but unused.

Housekeeping: The changelog fragment follows the naming pattern and uses the right section. The commit prefix is fix(cli):. All checks passed on this head.

Needed before merge

  1. Assert error_code == "USAGE_ERROR" in the parsed JSON for the create refusals.
  2. Add an update test that omits --importance and checks the stored importance is unchanged.

Recommendation: merge after items 1 to 2.
The maintainer makes the final call.
This touches a CLI flag (--importance on create and update), so the merge is the maintainer's.


Generated by Claude Code

@markramm

Copy link
Copy Markdown
Collaborator

A note from the maintainer's loop: dev moved under this PR in a way that affects it, and the change is small.

#1544 merged a test, tests/test_cli_numeric_options_declare_a_range.py, that walks every registered command and fails for a numeric option with no declared range (#1541). The options this PR fixes are on that test's NOT_YET list. Once this PR declares their range, the test's stale-row check will fail until the rows are removed. So, after rebasing onto dev (the earlier review already asked for the rebase):

  1. Delete these rows from NOT_YET in that file:
    • ("pyrite create", "importance")
    • ("pyrite update", "importance")
  2. Set NOT_YET_PINNED_SIZE to the new length of NOT_YET (the test requires the two to match). Other PRs lower the same number, so if dev has moved again by the time you rebase, take dev's list, remove your rows, and count again.
  3. Check with .venv/bin/pytest tests/test_cli_numeric_options_declare_a_range.py -q.

Declare the range with min=/max= on the option itself (not clamp=True, and not a check in the command body): the test only counts a range that Typer refuses as a usage error, exit 2. Nothing else in the earlier review changes.

🤖 Generated with Claude Code

@markramm

Copy link
Copy Markdown
Collaborator

Automated note from the maintainer's conductor agent.

Thank you for your patience; this PR is still wanted. Since it was opened, #1570 made the service refuse an importance outside 1 to 10 on every entry type, but the CLI options themselves still declare no range: on dev, create --importance and update --importance in pyrite/cli/entry_commands.py have no min/max, and both are rows on the "not yet" list of the range test (tests/test_cli_numeric_options_declare_a_range.py, ("pyrite create", "importance") and ("pyrite update", "importance"); #1541). Your min=1, max=10 is that slice, and the other importance work in flight (#1633) leaves these two options to this PR.

To land it:

  1. Merge or rebase onto dev.
  2. Delete those two rows from the NOT_YET list in the range test. If NOT_YET_PINNED_SIZE is still in the file when you do, lower it by two; PR test: the numeric-option ratchet is its own pin; a range check refuses an added row (#1608, slice 1) #1614 is about to remove that number, and after it lands there is nothing else to edit.
  3. Add the two tests the earlier review asked for (the USAGE_ERROR code on an out-of-range value, and update without --importance still working).

A new head gets a fresh review within the hour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state: needs-author Changes requested on the current head: the next move is the author's

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create and update --importance accept out-of-range values

2 participants